package com.zhongwang.mms.module.jiaGongMaterial.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.TDept;
import com.zhongwang.mms.module.basic.dao.TWarehouseInfoDao;
import com.zhongwang.mms.module.basic.service.TDeptService;
import com.zhongwang.mms.module.jiaGongMaterial.dao.MaterialInDao;
import com.zhongwang.mms.module.jiaGongMaterial.model.JMaterialAllModel;
import com.zhongwang.mms.module.jiaGongMaterial.service.MaterialOffsetService;
import com.zhongwang.mms.module.jiaGongMaterial.service.MaterialStockService;
import com.zhongwang.mms.module.material.model.CompositeOutcomeModel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 原料出入库查询 控制层
 * @Author: China.wsg
 * @Date: 2020/04/01 11:23
 */
@Controller
@RequestMapping("/materialOffset")
public class MaterialOffsetController extends BaseController {

    @Autowired
    private MaterialStockService materialStockService;

    @Autowired
    private MaterialOffsetService materialOffsetService;
    /**
     * 页面
     *
     * @return 页面路径
     */
    @GetMapping("/page")
    public String page() {

        return "jiaGongMaterial/materialOffset/page";
    }
    /**
     * 获取单据明细（根据检索条件）
     *
     * @param jMaterialAllModel 检索条件
     * @return
     */
    @ResponseBody
    @PostMapping("/orderDetailInfo")
    public JsonResult getOrderDetailByQuery(JMaterialAllModel jMaterialAllModel) {
        startPage();
        List<JMaterialAllModel> list = materialStockService.findCompositeOutcome(jMaterialAllModel);
        return jsonResult(list);
    }
    /**
     * 明细红冲（批量红冲）
     *
     * @param arr 明细Id集合
     * @return
     */
    @ResponseBody
    @PostMapping("/redDetailTogether")
    public JsonResult redDetailTogether(@RequestBody List<Integer> arr) {

        JsonResult jsonResult = new JsonResult();
        String msg = materialOffsetService.redDetailTogether(arr);
        if (!msg.contains("红冲失败")) {
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
        }
        jsonResult.setMsg(msg);
        return jsonResult;
    }

    /**
     * 明细红冲（单条红冲）
     *
     * @param odaId 明细Id
     * @return
     */
    @ResponseBody
    @PostMapping("/redDetailSingle")
    public JsonResult redDetailSingle(Integer odaId) {
        JsonResult jsonResult = new JsonResult();
        String msg = materialOffsetService.redDetailSingle(odaId);
        if (!msg.contains("红冲失败")) {
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
        }
        jsonResult.setMsg(msg);
        return jsonResult;
    }

}
